﻿using ChiWalker.Dynamics;
using ChiWalker.Helpers;
using ChiWalker.Settings;
using ChiWalker.Spell;
using ChiWalker.Utilities;
using CommonBehaviors.Actions;
using Styx;
using Styx.CommonBot;
using Styx.TreeSharp;

namespace ChiWalker.Routines.Druid
{
    internal class Common
    {
        [Behavior(BehaviorType.Rest)]
        [Spec(WoWSpec.DruidBalance)]
        [Spec(WoWSpec.None)]
        [Class(WoWClass.Druid)]
        public static Composite RestRoutine()
        {
            return
                new Decorator(ret => !StyxWoW.Me.IsDead && !StyxWoW.Me.IsGhost,
                    new PrioritySelector(
                        WaitFor.WaitForCast(),
                        new Decorator(ret => StyxWoW.Me.HasAura("Food") && StyxWoW.Me.HealthPercent <= 95,
                            new ActionAlwaysSucceed()),
                        new CastOnSelf(Spell.Rejuvenation,
                            ret =>
                                StyxWoW.Me.HealthPercent <= 75 && !StyxWoW.Me.HasAura("Rejuvenation")),
                        new CastOnSelf(Spell.HealingTouch, ret => StyxWoW.Me.HealthPercent <= 75),
                        //We cant eat or drink if swimming
                        new Decorator(
                            ret =>
                                !StyxWoW.Me.IsSwimming &&
                                StyxWoW.Me.HealthPercent <= ChiWalkerSettings.Instance.EatingPct &&
                                !StyxWoW.Me.HasAura("Food") && !Rest.NoFood,
                            new PrioritySelector(
                                Movement.StopMoving(),
                                new Action(ret => Rest.FeedImmediate())
                                )
                            )
                        )
                    );
        }
    }
}